#ifndef _GAME_H_
#define _GAME_H_

#include <windows.h>
#include <d3d9.h>


#include "DirectX.h"
#include "DxInput.h"
#include "Timer.h"

//
// Screen resolution
//
#define GL_GAME_SCREEN_RESOLUTION_640_480_24   0
#define GL_GAME_SCREEN_RESOLUTION_800_600_24   1
#define GL_GAME_SCREEN_RESOLUTION_1024_768_24  2

#define GL_GAME_SCREEN_RESOLUTION_640_480_32   10
#define GL_GAME_SCREEN_RESOLUTION_800_600_32   11
#define GL_GAME_SCREEN_RESOLUTION_1024_768_32  12


/**--------------------------------------------------------
*Program/Project : GameMario
*Written by : 
*Email :
*Created date : 7/10/2012
*Modified by :
*Modified date :
*Version : 1.0
*Description : Lop khoi tao game
--------------------------------------------------------**/

class Game
{
protected:
	

	DWORD _DeltaTime;		// Time between the last frame and current frame
	int _Mode;				// Screen mode 
	int _IsFullScreen;		// Is running in fullscreen mode?
	int _FrameRate;

	int _ScreenWidth;
	int _ScreenHeight;
	int _Depth;

	D3DFORMAT _BackBufferFormat;	//Format of buffer

	HINSTANCE _hInstance;			// Handle of the game instance
	HWND _hWnd;						// Handle of the Game Window

	LPWSTR _Name;					// Name of game will be used as Window Class Names

	/*---------------Init Game--------------*/
	void _SetScreenDimension(int Mode);
	void _InitWindow();
	void _InitDirectX();
	void _InitKeyboard();



	/*---------------Run Function------------*/
	static LRESULT CALLBACK _WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	
	void _RenderFrame();	// Render a single frame

	void _ProcessKeyBoard();	// Get state of keyboard
	



	// Place holder for sub classes
	virtual void RenderFrame(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 BackBuffer, int Delta);	// Draw frame
	virtual void LoadResources(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 BackBuffer);			// Load resource
	virtual void ProcessInput(LPDIRECT3DDEVICE9 d3ddv, int Delta);	// Input keyboard for collision

	

	//them vao
	DirectX *d3d;
	virtual void update(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 BackBuffer, int Delta);
	DxInput *p_input;
	Timer *p_time;
	float TPF;			//Time per frame
	void UpdateGame();


public:
	LPDIRECT3D9 GetDirectX();				// Get direct3D object
	LPDIRECT3DDEVICE9 GetDevice();			// Get direct device
	LPDIRECT3DSURFACE9 GetBackBuffer();		// Get direct buffer

	int GetMode();				// Get Screen Mode

	int GetScreenWidth();		// Get Screen width
	int GetScreenHeight();		// Get Screen height
	int GetDepth();				// Get Screen depth
	float GetFPS();				// Get rate game, game quickly or slowly
	int FrameRate;				// Desired frame rate of game

	//khoi tao lop game(thuc the, ten, che do man hinh, co fullscreen hay k, toc do frame)
	Game(HINSTANCE hInstance, LPWSTR Name, int Mode, int IsFullscreen, int FrameRate);
	~Game();					//huy lop game

	void Init();				// Initialize the game with set parameters

	void Run();					// Run game

	void End();
};

#endif